home *** CD-ROM | disk | FTP | other *** search
/ Aminet 21 / Aminet 21 (1997)(GTI - Schatztruhe)[!][Oct 1997].iso / Aminet / dev / misc / gms_dev.lha / GMS / Source / C / Screens / Sprites.c < prev   
Encoding:
C/C++ Source or Header  |  1997-07-09  |  2.3 KB  |  84 lines

  1. /*
  2. ** Name:      Sprite Example
  3. ** Author:    Paul Manias
  4. ** Copyright: DreamWorld Productons (c) 1996-1997.
  5. ** SAS/C:     1> sc Sprites.c link startup=LIB:gms.o data=far nostackcheck
  6. ** Dice:      1> dcc -l0 -mD gms.o Sprites.c -o Sprites
  7. **
  8. ** This example shows you how to set up a 16 colour OCS sprite with a
  9. ** doubled X axis (32 pixels width).  Those with hardware experience will
  10. ** know that it takes 4 sprite banks to do this successfully in OCS, which
  11. ** leaves you with another 4 banks to do with what you will.  You can do
  12. ** this same demo in AGA with just 2 banks used.
  13. ** 
  14. */
  15.  
  16. #include <proto/games.h>
  17.  
  18. extern struct GMSBase *GMSBase;
  19. APTR   PREFSNAME = DEFAULT;
  20.  
  21. ULONG Palette[] = {
  22.    0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,
  23.    0x000000,0x608080,0x406060,0x304040,0xC0C000,0x908000,0x807000,0x605000,
  24.    0x10C020,0x005000,0xB000B0,0x600060,0xF02000,0x901000,0xB0B0B0,0xF0F0F0,
  25.    0x00B0F0,0x006080,0x506080,0x90B0F0,0xF0F000,0xE0E000,0xB0A000,0x504000
  26. };
  27.  
  28. void main(void)
  29. {
  30.   struct Sprite *Sparkie;
  31.   struct GameScreen *GameScreen;
  32.   APTR  SparkieData;
  33.   UWORD Timer=0;
  34.   ULONG ZBXY=0;
  35.  
  36.   if (SparkieData = SmartLoad("GMS:demos/data/RAW.Sparkie",0,MEM_VIDEO)) {
  37.   
  38.     if (GameScreen = AddScreenTags(TAGS_GAMESCREEN,NULL,
  39.        GSA_Palette,Palette,
  40.        GSA_AmtColours,32,
  41.        GSA_Planes,1,
  42.        GSA_Attrib,SPRITES|NOSCRBDR,
  43.        TAGEND)) {
  44.   
  45.        if (Sparkie = InitSpriteTags(GameScreen,TAGS_SPRITE,NULL,
  46.           SPA_Data,SparkieData,
  47.           SPA_XCoord,100,
  48.           SPA_YCoord,100,
  49.           SPA_Width,16,
  50.           SPA_Height,21,
  51.           SPA_AmtColours,16,
  52.           SPA_ColStart,16,
  53.           SPA_Planes,2,
  54.           SPA_ScrMode,LORES,
  55.           SPA_Attrib,XLONG,
  56.           TAGEND)) {
  57.  
  58.           UpdateSprite(GameScreen,Sparkie);
  59.           ShowScreen(GameScreen);
  60.   
  61.           InitJoyPorts();
  62.   
  63.           while (!(ZBXY&MB_LMB)) {
  64.   
  65.              if (++Timer&0x1) {
  66.                 if (Sparkie->Frame == 5) Sparkie->Frame = 0;
  67.                 else Sparkie->Frame++;
  68.              }
  69.   
  70.              ZBXY = ReadJoyPort(JPORT1,JT_ZBXY);
  71.              Sparkie->XPos += GetX(ZBXY);
  72.              Sparkie->YPos += GetY(ZBXY);
  73.              WaitVBL();
  74.              UpdateSprite(GameScreen, Sparkie);
  75.           }
  76.        FreeSprite(Sparkie);
  77.        }
  78.     DeleteScreen(GameScreen);
  79.     }
  80.   FreeMemBlock(SparkieData);
  81.   }
  82. }
  83.  
  84.